#ifndef __SYNTAX_H
#define __SYNTAX_H
#include "stdtype.h"
#include "mstring.h"

/* type of start-stop symbol for matching rule */
#define MX_SYNTAX_TYPE_SYMMETRIC 0  // symmetric nesting, like `" " " `"
#define MX_SYNTAX_TYPE_SEQUENTIAL 1 // sequential nesting, like `$( $() `) $()

typedef struct mx_syntax_cell mx_syntax_cell_t, *mx_syntax_cell_pt;

struct mx_syntax_cell
{
    mx_uint8_t type;        // MX_SYNTAX_TYPE_*
    mx_bool_t snest;        // whether support syntax nesting, like $( $()${} ) support syntax nesting, '' or ${} not support syntax nesting
    mx_bool_t sbreak;       // whether support break by other start-stop symbol, like $var"string", only effect on type=MX_SYNTAX_TYPE_SEQUENTIAL && snest=mx_false
    mx_string_pt start;     // the start symbol
    mx_string_pt stop;      // the stop symbol, if you want stop with others ss symbol, you can set it with unprintable char and set the sbreak = mx_true
    /* @param ctx: the context inner start-stop symbol
       @note: `resbuf` and `ctx` are both local buffer with size = `bufsize`, you can modify and return it as you need
       @return: the result string */
    mx_string_pt (*callback) (mx_syntax_cell_pt pcell, mx_string_pt ctx, mx_string_pt resbuf, mx_usize_t bufsize);
};

/* TODO */
// typedef struct
// {
//     mx_string_pt symbol;
// } mx_syntax_expr_t, *mx_syntax_expr_pt;

/* analysis a string and explain the cells in it */
mx_string_pt mx_syntax_cell_parser (mx_syntax_cell_pt cells, mx_usize_t clen, mx_string_pt str,
                                    mx_string_pt resbuf, mx_usize_t bufsize);

#endif
